//
//  SelectBankSheetView.m
//  YinPiao
//
//  Created by figs on 15/11/20.
//  Copyright © 2015年 YinPiao. All rights reserved.
//

#import "SelectBankSheetView.h"
#import <QuartzCore/QuartzCore.h>

#define kDuration 0.3

//@interface SelectBankSheetView ()
//
//@end

@implementation SelectBankSheetView
@synthesize bankPicker;
- (id)initWithTitle:(NSString *)title delegate:(id /*<UIActionSheetDelegate>*/)delegate
{
//    self.delegate = delegate;
    self.bankPicker.dataSource = self;
    self.bankPicker.delegate = self;
    
    //加载数据
    bankNamesArray = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BankAndType.plist" ofType:nil]];//银行类型
    banktypesArray = [[bankNamesArray objectAtIndex:1] objectForKey:@"Type"];//银行卡
    
    //初始化默认数据
    self.Bank=[[SelectBank alloc] init];
    self.Bank.bankName=[[banktypesArray objectAtIndex:0]objectForKey:@"name"];
    self.Bank.bankType=[[bankNamesArray objectAtIndex:0]objectForKey:@"Bank"];
    return self;
}

- (void)showInView:(UIView *) view
{
    CATransition *animation = [CATransition  animation];
    animation.delegate = self;
    animation.duration = kDuration;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromTop;
    [self.view setAlpha:1.0f];
    [self.view.layer addAnimation:animation forKey:@"SelectBankSheetView"];
    
    //    self.frame = CGRectMake(0, view.frame.size.height - self.frame.size.height, self.frame.size.width, self.frame.size.height-64);
    self.view.frame = CGRectMake(0, view.frame.size.height - self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    [view addSubview:self.view];
    
//    [view addSubview:self];
}


#pragma mark - PickerView lifecycle

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    switch (component) {
        case 0:
           return [banktypesArray count];
//            return 11;
            break;
        case 1:
           return [bankNamesArray count];
//            return 2;
            break;
        default:
            return 0;
            break;
    }
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    switch (component) {
        case 0:
            return [[banktypesArray objectAtIndex:row] objectForKey:@"name"];
//            return @"11";
            break;
        case 1:
            return [[bankNamesArray objectAtIndex:row] objectForKey:@"Bank"];
//             return @"22";
            break;
        default:
            return nil;
            break;
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//    switch (component) {
//
//        case 0:
////            bankNamesArray = [[banktypesArray objectAtIndex:row] objectForKey:@"name"];
//            [self.bankPicker selectRow:0 inComponent:1 animated:NO];
//            [self.bankPicker reloadComponent:1];
////            self.Bank.bankType=[[banktypesArray objectAtIndex:row] objectForKey:@"name"];
//           self.Bank.bankName=[[bankNamesArray objectAtIndex:row] objectForKey:@"Bank"];
//            break;
//        case 1:
//      banktypesArray= [[bankNamesArray objectAtIndex:row] objectForKey:@"Bank"];
//            
//            break;
//        default:
//            break;
//    }
}
#pragma mark - Button lifecycle

- (IBAction)cancelButton:(id)sender {
    NSLog(@"111");
    CATransition *animation = [CATransition  animation];
    animation.delegate = self;
    animation.duration = kDuration;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromBottom;
//    [self.view setAlpha:0.0f];
//    [self.view.layer addAnimation:animation forKey:@"SelectBankSheetView"];
//    [self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:kDuration];
//    if(self.delegate) {
//        [self.delegate actionSheet:self clickedButtonAtIndex:0];
//    }
}

- (IBAction)sureButton:(id)sender {
    NSLog(@"111");
    [self dismissViewControllerAnimated:YES completion:^{
    
    }];
    
//    CATransition *animation = [CATransition  animation];
//    animation.delegate = self;
//    animation.duration = kDuration;
//    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    animation.type = kCATransitionPush;
//    animation.subtype = kCATransitionFromBottom;
//    [self.view setAlpha:0.0f];
//    [self.view.layer addAnimation:animation forKey:@"SelectBankSheetView"];
//    [self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:kDuration];
//    if(self.delegate) {
//        [self.delegate actionSheet:self clickedButtonAtIndex:1];
//    }
    
}


//- (void)viewDidLoad {
//    [super viewDidLoad];
//    // Do any additional setup after loading the view from its nib.
//}
//
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
